﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class ManageTables : Form
    {
        public ManageTables()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gbListTable.AutoSize = true;
         
            this.AutoScroll = true;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.WindowState = FormWindowState.Maximized;
            Load_All_Table();

        }

        #region Custom Function
        private void Load_All_Table()
        {
            int width = this.Width;
            int height = this.Height;
            bool flag = false;
            int j = 0, count_line = 0;
            for (int i = 0; i < 21; i++)
            {
                if (Check_New_Line(i) == false)
                {
                    if (flag == false)
                    {
                        Create_Table(new Point(i * (width - 35) / 7, 40), (i + 1).ToString());
                    }
                    else
                    {
                        Create_Table(new Point(j * (width - 35) / 7, (width - 35) / 7 * count_line), (i + 1).ToString());
                        j++;
                    }
                }
                else
                {
                    flag = true;
                    j = 0;
                    count_line++;
                    Create_Table(new Point(j * (width - 35) / 7, (width - 35) / 7 * count_line), (i + 1).ToString());
                    j++;

                }
            }
        }
        private void Create_Table(Point p, String name)
        {
            int width = this.Width;
            int height = this.Height;
            Button bt = new Button();
            bt.Text = name;
            bt.Font = new Font("Arial", bt.Height + 50);
            bt.Width = width / 7;
            bt.Height = width / 7;
            bt.Location = p;
            bt.BackColor = ColorTranslator.FromHtml("#2ecc71");
            bt.ForeColor = ColorTranslator.FromHtml("#F4F7F9");
            bt.Click += new EventHandler(clickTable);
            gbListTable.Controls.Add(bt);
        }
        private bool Check_New_Line(int index)
        {
            if (index % 7 == 0 && index != 0)
            {
                return true;
            }
            return false;
        }
        #endregion

        private void clickTable(object sender, EventArgs e)
        {
            Button button = sender as Button;
            button.BackColor = ColorTranslator.FromHtml("#f4726d");
            button.ForeColor = ColorTranslator.FromHtml("#F4F7F9");
        }
    



    }
}
